import { resultSuccess, doCustomTimes } from '../_util';

function getMenuKeys() {
  const keys = ['dashboard', 'console', 'workplace', 'basic-form', 'step-form', 'detail'];
  const newKeys = [];
  doCustomTimes(parseInt(Math.random() * 6), () => {
    const key = keys[Math.floor(Math.random() * keys.length)];
    newKeys.push(key);
  });
  return Array.from(new Set(newKeys));
}

const roleList = (pageSize) => {
  const result: any[] = [];
  doCustomTimes(pageSize, () => {
    result.push({
      id: '@integer(10,100)',
      name: '@cname()',
      explain: '@cname()',
      isDefault: '@boolean()',
      menu_keys: getMenuKeys(),
      create_date: `@date('yyyy-MM-dd hh:mm:ss')`,
      'status|1': ['normal', 'enable', 'disable'],
    });
  });
  return result;
};

export default [
  {
    url: '/api/role/list',
    timeout: 1000,
    method: 'POST',
    response: ({ query }) => {
      const { current = 1, size = 10 } = query;
      return resultSuccess({
          code: "000000",
          mesg: "处理成功",
          timestamp: "2023-10-30T16:06:47.628Z",
          data: {
            records: [{
              id: 101,
              createdBy: "admin",
              updatedBy: "admin",
              createdTime: "2019-08-04 19:07:36",
              updatedTime: "2019-08-04 19:07:38",
              deleted: 0,
              configCode: "DEFAULT_PASSWORD",
              configValue: "yZYkBZe4dCjSuHGR+b3q5A==",
              configExplain: "默认密码 123456"
            }, {
              id: 102,
              createdBy: "admin",
              updatedBy: "admin",
              createdTime: "2019-08-04 19:09:24",
              updatedTime: "2019-08-04 19:09:25",
              deleted: 0,
              configCode: "RESET_PASSWORD",
              configValue: "yZYkBZe4dCjSuHGR+b3q5A==",
              configExplain: "重置密码 123456"
            }],
            total: 2,
            size: 20,
            current: 1,
            orders: [],
            optimizeCountSql: true,
            searchCount: true,
            maxLimit: null,
            countId: null,
            pages: 1
          },
          fail: false,
          success: true
      });
    },
  },
];
